#include<iostream>
#include<cmath>
using namespace std;
int main(){
	long int n,ans=-9999999;
	int enter[20001],dp[20001]={0};
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>enter[i];
	}
	for(int i=0;i<n;i++){
		dp[i]=max(dp[i-1]+enter[i],enter[i]);
		if(ans<dp[i])
			ans=dp[i];
	}
	cout<<ans;
}
